<?php

namespace app\api\controller;
use app\common\controller\Api;
use think\Validate;
use think\Loader;
use think\Page;
use think\Db;
use \app\admin\model\ConsultingCategory;
class Chat extends Api
{ 
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $user_id = 0;

    public function _initialize()
    {
        parent::_initialize();
        $this->user_id = $this->auth->id;
    }

    /**
     * @MethodName 獲取加諮詢分類列表
     * @Author     Allen
     * @DateTime   2021-10-04T14:55:12+0800
     * @param      string
     * @return     [array]
     */
    public function getConsultingCategoryList($value='')
    {
        $model = new ConsultingCategory;
        $list = $model->field('id,name')->where(['parent_id'=>0])->order('weigh desc,id desc')->select();
        foreach ($list as $key => &$value) {
            $value['child'] = $model->field('id,name')->where(['parent_id'=>$value['id']])->order('weigh desc,id desc')->select();
        }
        unset($value);
        $this->success('請求成功',$list);
    }

    /**
     * [setConsultingHistory 設置資訊歷史記錄]
     * @MethodName
     * @Author     Allen
     * @DateTime   2021-10-28T00:17:39+0800
     * @param      string                   $value [description]
     */
    public function setConsultingHistory($value='')
    {
        $consulting_category_id = $this->request->post("consulting_category_id", 0);
        if ( !$consulting_category_id ) {
            $this->success('操作成功');
        }
        db('consulting_history')->insert(['user_id'=>$this->user_id,'consulting_category_id'=>$consulting_category_id,'createtime'=>time()]);
        $this->success('操作成功');
    }
}